package com.hczt.fire.server.config.sercurity.interceptor;

import com.hczt.fire.server.config.sercurity2.MyRequestWrapper;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 精诚所至，金石为开。
 * 石の上にも三年;陽気の発する所金石亦透る。
 * Faith moves mountains.
 *
 * @author marvin.ma
 * @create 2017-11-30 18:17
 * @desc ${DESCRIPTION}
 **/
public class LoginInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        MyRequestWrapper myRequestWrapper = new MyRequestWrapper(request);

        String body = myRequestWrapper.getBody();
        String clientIP = myRequestWrapper.getRemoteHost();
        int clientPort = request.getRemotePort();
        String uri = myRequestWrapper.getRequestURI();

        System.out.println(body);
        System.out.println(clientIP);
        System.out.println(clientPort);
        System.out.println(uri);
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
